%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This file is part of the book
%%
%% Algorithmic Graph Theory
%% http://code.google.com/p/graphbook/
%%
%% Copyright (C) 2009--2013 Minh Van Nguyen <mvngu.name@gmail.com>
%%
%% See the file COPYING for copying conditions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{algorithmic}[1]
%% input and output
\Require Positive integer $n$ and integer $N$ with 
  $0 \leq N \leq \binom{n}{2}$.
\Ensure A random graph from $G(n,N)$.
%%
%% algorithm body
\State $G \gets \overline{K_n}$
\State $E \gets \left\{e_0, e_1, \dots, e_{\binom{n}{2} - 1}\right\}$
\For{$i \gets 0, 1, \dots, N - 1$}
  \State $r \gets$ draw uniformly at random from $\left\{0, 1, \dots, \binom{n}{2} - 1\right\}$
  \While{\rm $e_r$ is an edge of $G$}
    \State $r \gets$ draw uniformly at random from $\left\{0, 1, \dots, \binom{n}{2} - 1\right\}$
  \EndWhile
  \State add edge $e_r$ to $G$
\EndFor
\State \Return $G$
\end{algorithmic}
